SET SERVEROUTPUT ON SIZE 1000000;
SET VERIFY OFF

DECLARE
	l_total_extracted	NUMBER;
	l_total_imported	NUMBER;				
	l_func_id			VARCHAR2(100):='CAPFNDREC_EMPLOYEE';

BEGIN
	SELECT COUNT(1)
	INTO l_total_extracted   
	FROM
		PER_BUSINESS_GROUPS		B,
		PER_ALL_PEOPLE_F		P,
		PER_PERSON_TYPES		T
	WHERE	SUBSTR(B.Name,4,4)	=	UPPER('&1')
	AND		P.Business_Group_ID	=	B.Business_Group_ID
	AND		P.Person_Type_ID	=	T.Person_Type_ID
	AND		SYSDATE		BETWEEN		P.Effective_Start_Date
						AND			NVL(P.Effective_End_Date,TO_DATE('47121231','YYYYMMDD'))
	ORDER BY	P.Person_ID;
	
	SELECT COUNT(1) 
	INTO l_total_imported
	FROM CRST_FND_PER_ALL_PEOPLE;

	dbms_output.put_line('Function: '||l_func_id);		
	dbms_output.put_line('Total Extracted: '||TO_CHAR(l_total_extracted)) ;
	dbms_output.put_line('Total Imported:  '||TO_CHAR(l_total_imported));
	IF l_total_extracted <> l_total_imported THEN
		dbms_output.put_line('Error: No. of Records do not match!');
	END IF;		
						
EXCEPTION
	WHEN OTHERS THEN	
		dbms_output.put_line('Function Error: '||l_func_id);			
END;
/
